package com.hex.ds.hdrs.label.controller;

import com.hex.bigdata.hbda.annotation.Log;
import com.hex.bigdata.hbda.base.Page;
import com.hex.ds.hdrs.label.converter.ILabelInfoVoConverter;
import com.hex.ds.hdrs.label.dto.LabelInfoDto;
import com.hex.ds.hdrs.label.service.ILabelInfoService;
import com.hex.ds.hdrs.label.vo.LabelInfoVo;
import com.hex.ds.hdrs.label.vo.query.LabelInfoQueryVo;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotEmpty;
import java.util.List;

/**
 * @Package: com.hex.ds.hdrs.label.controller
 * @ClassName LabelInfoController
 * @Description: 标签关联WEB接口
 * @Author: wz.li
 * @Date 2023/4/19 10:47
 * @Version v2.0.2
 **/
@Slf4j
@RestController
@RequestMapping("/api/labelInfo")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class LabelInfoController {

    private final ILabelInfoService labelInfoService;

    private final ILabelInfoVoConverter labelInfoVoConverter;

    /*
     * @Method: queryListByPage <br>
     * @Param: [labelInfoQueryVo, page] <br>
     * @Return: org.springframework.http.ResponseEntity<java.lang.Object> <br>
     * @Description：queryListByPage<br>
     * @Author： wz.li<br>
     * @Date： 2023/4/19 10:47 <br>
     * @Version： V2.0.2<br>
     */
    @GetMapping
    @ApiOperation("分页查询-标签")
    public ResponseEntity<Object> queryListByPage(LabelInfoQueryVo labelInfoQueryVo, Page page) {
        log.debug("进入【LabelInfoController.queryListByPage】参数: labelInfoQueryVo = {}, page = {}", labelInfoQueryVo, page);
        LabelInfoDto labelInfoDto = labelInfoVoConverter.toLabelInfoDtoForQry(labelInfoQueryVo);
        return ResponseEntity.ok(labelInfoService.queryListByPage(labelInfoDto, page));
    }

    /*
     * @Method: add <br>
     * @Param: [labelInfoVo] <br>
     * @Return: org.springframework.http.ResponseEntity<java.lang.Object> <br>
     * @Description：新增标签<br>
     * @Author： wz.li<br>
     * @Date： 2023/4/19 10:49 <br>
     * @Version： V2.0.2<br>
     */
    @PostMapping
    @Log("新增标签")
    @ApiOperation("新增标签")
    public ResponseEntity<Object> add(@RequestBody LabelInfoVo labelInfoVo) {
        log.debug("进入【LabelInfoController.add】，参数: labelInfoVo = {}", labelInfoVo);
        labelInfoService.add(labelInfoVoConverter.toLabelInfoDto(labelInfoVo));
        return new ResponseEntity("新增成功", HttpStatus.OK);
    }

    /*
     * @Method: modifyById <br>
     * @Param: [labelInfoVo] <br>
     * @Return: org.springframework.http.ResponseEntity<java.lang.Object> <br>
     * @Description：更新标签<br>
     * @Author： wz.li<br>
     * @Date： 2023/4/19 11:21 <br>
     * @Version： V2.0.2<br>
     */
    @PutMapping
    @Log("更新标签")
    @ApiOperation("更新标签")
    public ResponseEntity<Object> modifyById(@RequestBody LabelInfoVo labelInfoVo) {
        log.debug("进入【LabelInfoController.modifyById】参数:labelInfoVo = {}", labelInfoVo);
        labelInfoService.modifyById(labelInfoVoConverter.toLabelInfoDto(labelInfoVo));
        return new ResponseEntity("修改成功", HttpStatus.OK);
    }

    /*
     * @Method: batchRemoveById <br>
     * @Param: [pkIds] <br>
     * @Return: org.springframework.http.ResponseEntity<java.lang.Object> <br>
     * @Description：批量删除标签<br>
     * @Author： wz.li<br>
     * @Date： 2023/4/19 11:21 <br>
     * @Version： V2.0.2<br>
     */
    @DeleteMapping
    @Log("批量删除标签")
    @ApiOperation("批量删除标签")
    public ResponseEntity<Object> batchRemoveById(@RequestBody @NotEmpty List<String> pkIds) {
        log.debug("进入【LabelInfoController.batchRemoveById】参数:pkIds = {}", pkIds);
        labelInfoService.batchRemoveById(pkIds);
        return new ResponseEntity("删除成功", HttpStatus.OK);
    }

    /*
     * @Method: batchEnableById <br>
     * @Param: [pkIds] <br>
     * @Return: org.springframework.http.ResponseEntity<java.lang.Object> <br>
     * @Description：批量启用标签<br>
     * @Author： wz.li<br>
     * @Date： 2023/4/19 11:22 <br>
     * @Version： V2.0.2<br>
     */
    @Log("批量启用标签")
    @PutMapping("/enable")
    @ApiOperation("批量启用标签")
    public ResponseEntity<Object> batchEnableById(@RequestBody @NotEmpty List<String> pkIds) {
        log.debug("进入【LabelInfoController.batchEnableById】参数:pkIds = {}", pkIds);
        labelInfoService.batchEnableById(pkIds);
        return new ResponseEntity("启用成功", HttpStatus.OK);
    }

    /*
     * @Method: batchDisableById <br>
     * @Param: [pkIds] <br>
     * @Return: org.springframework.http.ResponseEntity<java.lang.Object> <br>
     * @Description：批量停用标签<br>
     * @Author： wz.li<br>
     * @Date： 2023/4/19 11:22 <br>
     * @Version： V2.0.2<br>
     */
    @Log("批量停用标签")
    @PutMapping("/disable")
    @ApiOperation("批量停用标签")
    public ResponseEntity<Object> batchDisableById(@RequestBody @NotEmpty List<String> pkIds) {
        log.debug("进入【LabelInfoController.batchDisableById】参数:pkIds = {}", pkIds);
        labelInfoService.batchDisableById(pkIds);
        return new ResponseEntity("停用成功", HttpStatus.OK);
    }

    /*
     * @Method: queryList <br>
     * @Param: [labelInfoQueryVo] <br>
     * @Return: org.springframework.http.ResponseEntity<java.lang.Object> <br>
     * @Description：不分页查询标签<br>
     * @Author： wz.li<br>
     * @Date： 2023/4/19 11:23 <br>
     * @Version： V2.0.2<br>
     */
    @GetMapping("/queryList")
    @ApiOperation("不分页查询-标签")
    public ResponseEntity<Object> queryList(LabelInfoQueryVo labelInfoQueryVo) {
        log.debug("进入【LabelInfoController.labelInfoQueryVo】参数:labelInfoQueryVo = {}", labelInfoQueryVo);
        LabelInfoDto labelInfoDto = labelInfoVoConverter.toLabelInfoDtoForQry(labelInfoQueryVo);
        return new ResponseEntity(labelInfoService.queryList(labelInfoDto), HttpStatus.OK);
    }

    /*
     * @Method: checkLabelCode <br>
     * @Param: [labelInfoQueryVo] <br>
     * @Return: org.springframework.http.ResponseEntity<java.lang.Object> <br>
     * @Description：检查标签编码是否重复（平台必须唯一）<br>
     * @Author： wz.li<br>
     * @Date： 2023/7/12 11:46 <br>
     * @Version： V2.0.2<br>
     */
    @GetMapping("/checkLabelCode")
    @ApiOperation("检查标签编码是否重复")
    public ResponseEntity<Object> checkLabelCode(LabelInfoQueryVo labelInfoQueryVo) {
        log.debug("进入【LabelInfoController.checkLabelCode】参数:labelInfoQueryVo = {}", labelInfoQueryVo.getLabelCode());
        LabelInfoDto labelInfoDto = labelInfoVoConverter.toLabelInfoDtoForQry(labelInfoQueryVo);
        return new ResponseEntity(labelInfoService.checkLabelCode(labelInfoDto), HttpStatus.OK);
    }

}
